# the following is an example of how to use generic relationships in your app
# put this code in demo_app/models.py
# from utils/models3.py
# demo_app/models3.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from utils.models3 import object_relation_mixin_factory
from django.utils.encoding import python_2_unicode_compatible

FavoriteObjectMixin = object_relation_mixin_factory(is_required=True)
OwnerMixin = object_relation_mixin_factory(
    prefix='owner',
    prefix_verbose=_('Owner'),
    add_related_name=True,
    limit_content_type_choices_to={
        'model_in': ('user', 'institution')
    },
    is_required=True,
)

@python_2_unicode_compatible
class Like(FavoriteObjectMixin, OwnerMixin):
    class Meta:
        verbose_name = _('Like')
        verbose_name_plural = _('Likes')

    def __str__(self):
        return _('%(owner)s likes (obj)s' % {
            'owner': self.owner_content_object,
            'obj': self.content_object,
        })